fastq filesThis step is performed on the O2 cluster. The fastq file quality was checked using FastQC and MultiQC. They are aligned to Ensembl mm10 genome and counted using Salmon pseudoaligner. Output sf files were transfered from O2 to local machine for further processing in R.
suppressMessages(
c(library(DESeq2),
library(tximport),
library(gridExtra),
library(ensembldb),
library(EnsDb.Mmusculus.v79),
library(grid),
library(ggplot2),
library(lattice),
library(reshape),
library(mixOmics),
library(gplots),
library(RColorBrewer),
library(readr),
library(dplyr),
library(VennDiagram))
)
## Warning: package 'ensembldb' was built under R version 3.5.3
## Warning: package 'GenomicFeatures' was built under R version 3.5.3
## [1] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [4] "BiocParallel" "matrixStats" "Biobase"
## [7] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [10] "S4Vectors" "BiocGenerics" "parallel"
## [13] "stats4" "stats" "graphics"
## [16] "grDevices" "utils" "datasets"
## [19] "methods" "base" "tximport"
## [22] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [25] "BiocParallel" "matrixStats" "Biobase"
## [28] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [31] "S4Vectors" "BiocGenerics" "parallel"
## [34] "stats4" "stats" "graphics"
## [37] "grDevices" "utils" "datasets"
## [40] "methods" "base" "gridExtra"
## [43] "tximport" "DESeq2" "SummarizedExperiment"
## [46] "DelayedArray" "BiocParallel" "matrixStats"
## [49] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [52] "IRanges" "S4Vectors" "BiocGenerics"
## [55] "parallel" "stats4" "stats"
## [58] "graphics" "grDevices" "utils"
## [61] "datasets" "methods" "base"
## [64] "ensembldb" "AnnotationFilter" "GenomicFeatures"
## [67] "AnnotationDbi" "gridExtra" "tximport"
## [70] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [73] "BiocParallel" "matrixStats" "Biobase"
## [76] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [79] "S4Vectors" "BiocGenerics" "parallel"
## [82] "stats4" "stats" "graphics"
## [85] "grDevices" "utils" "datasets"
## [88] "methods" "base" "EnsDb.Mmusculus.v79"
## [91] "ensembldb" "AnnotationFilter" "GenomicFeatures"
## [94] "AnnotationDbi" "gridExtra" "tximport"
## [97] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [100] "BiocParallel" "matrixStats" "Biobase"
## [103] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [106] "S4Vectors" "BiocGenerics" "parallel"
## [109] "stats4" "stats" "graphics"
## [112] "grDevices" "utils" "datasets"
## [115] "methods" "base" "grid"
## [118] "EnsDb.Mmusculus.v79" "ensembldb" "AnnotationFilter"
## [121] "GenomicFeatures" "AnnotationDbi" "gridExtra"
## [124] "tximport" "DESeq2" "SummarizedExperiment"
## [127] "DelayedArray" "BiocParallel" "matrixStats"
## [130] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [133] "IRanges" "S4Vectors" "BiocGenerics"
## [136] "parallel" "stats4" "stats"
## [139] "graphics" "grDevices" "utils"
## [142] "datasets" "methods" "base"
## [145] "ggplot2" "grid" "EnsDb.Mmusculus.v79"
## [148] "ensembldb" "AnnotationFilter" "GenomicFeatures"
## [151] "AnnotationDbi" "gridExtra" "tximport"
## [154] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [157] "BiocParallel" "matrixStats" "Biobase"
## [160] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [163] "S4Vectors" "BiocGenerics" "parallel"
## [166] "stats4" "stats" "graphics"
## [169] "grDevices" "utils" "datasets"
## [172] "methods" "base" "lattice"
## [175] "ggplot2" "grid" "EnsDb.Mmusculus.v79"
## [178] "ensembldb" "AnnotationFilter" "GenomicFeatures"
## [181] "AnnotationDbi" "gridExtra" "tximport"
## [184] "DESeq2" "SummarizedExperiment" "DelayedArray"
## [187] "BiocParallel" "matrixStats" "Biobase"
## [190] "GenomicRanges" "GenomeInfoDb" "IRanges"
## [193] "S4Vectors" "BiocGenerics" "parallel"
## [196] "stats4" "stats" "graphics"
## [199] "grDevices" "utils" "datasets"
## [202] "methods" "base" "reshape"
## [205] "lattice" "ggplot2" "grid"
## [208] "EnsDb.Mmusculus.v79" "ensembldb" "AnnotationFilter"
## [211] "GenomicFeatures" "AnnotationDbi" "gridExtra"
## [214] "tximport" "DESeq2" "SummarizedExperiment"
## [217] "DelayedArray" "BiocParallel" "matrixStats"
## [220] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [223] "IRanges" "S4Vectors" "BiocGenerics"
## [226] "parallel" "stats4" "stats"
## [229] "graphics" "grDevices" "utils"
## [232] "datasets" "methods" "base"
## [235] "mixOmics" "MASS" "reshape"
## [238] "lattice" "ggplot2" "grid"
## [241] "EnsDb.Mmusculus.v79" "ensembldb" "AnnotationFilter"
## [244] "GenomicFeatures" "AnnotationDbi" "gridExtra"
## [247] "tximport" "DESeq2" "SummarizedExperiment"
## [250] "DelayedArray" "BiocParallel" "matrixStats"
## [253] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [256] "IRanges" "S4Vectors" "BiocGenerics"
## [259] "parallel" "stats4" "stats"
## [262] "graphics" "grDevices" "utils"
## [265] "datasets" "methods" "base"
## [268] "gplots" "mixOmics" "MASS"
## [271] "reshape" "lattice" "ggplot2"
## [274] "grid" "EnsDb.Mmusculus.v79" "ensembldb"
## [277] "AnnotationFilter" "GenomicFeatures" "AnnotationDbi"
## [280] "gridExtra" "tximport" "DESeq2"
## [283] "SummarizedExperiment" "DelayedArray" "BiocParallel"
## [286] "matrixStats" "Biobase" "GenomicRanges"
## [289] "GenomeInfoDb" "IRanges" "S4Vectors"
## [292] "BiocGenerics" "parallel" "stats4"
## [295] "stats" "graphics" "grDevices"
## [298] "utils" "datasets" "methods"
## [301] "base" "RColorBrewer" "gplots"
## [304] "mixOmics" "MASS" "reshape"
## [307] "lattice" "ggplot2" "grid"
## [310] "EnsDb.Mmusculus.v79" "ensembldb" "AnnotationFilter"
## [313] "GenomicFeatures" "AnnotationDbi" "gridExtra"
## [316] "tximport" "DESeq2" "SummarizedExperiment"
## [319] "DelayedArray" "BiocParallel" "matrixStats"
## [322] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [325] "IRanges" "S4Vectors" "BiocGenerics"
## [328] "parallel" "stats4" "stats"
## [331] "graphics" "grDevices" "utils"
## [334] "datasets" "methods" "base"
## [337] "readr" "RColorBrewer" "gplots"
## [340] "mixOmics" "MASS" "reshape"
## [343] "lattice" "ggplot2" "grid"
## [346] "EnsDb.Mmusculus.v79" "ensembldb" "AnnotationFilter"
## [349] "GenomicFeatures" "AnnotationDbi" "gridExtra"
## [352] "tximport" "DESeq2" "SummarizedExperiment"
## [355] "DelayedArray" "BiocParallel" "matrixStats"
## [358] "Biobase" "GenomicRanges" "GenomeInfoDb"
## [361] "IRanges" "S4Vectors" "BiocGenerics"
## [364] "parallel" "stats4" "stats"
## [367] "graphics" "grDevices" "utils"
## [370] "datasets" "methods" "base"
## [373] "dplyr" "readr" "RColorBrewer"
## [376] "gplots" "mixOmics" "MASS"
## [379] "reshape" "lattice" "ggplot2"
## [382] "grid" "EnsDb.Mmusculus.v79" "ensembldb"
## [385] "AnnotationFilter" "GenomicFeatures" "AnnotationDbi"
## [388] "gridExtra" "tximport" "DESeq2"
## [391] "SummarizedExperiment" "DelayedArray" "BiocParallel"
## [394] "matrixStats" "Biobase" "GenomicRanges"
## [397] "GenomeInfoDb" "IRanges" "S4Vectors"
## [400] "BiocGenerics" "parallel" "stats4"
## [403] "stats" "graphics" "grDevices"
## [406] "utils" "datasets" "methods"
## [409] "base" "VennDiagram" "futile.logger"
## [412] "dplyr" "readr" "RColorBrewer"
## [415] "gplots" "mixOmics" "MASS"
## [418] "reshape" "lattice" "ggplot2"
## [421] "grid" "EnsDb.Mmusculus.v79" "ensembldb"
## [424] "AnnotationFilter" "GenomicFeatures" "AnnotationDbi"
## [427] "gridExtra" "tximport" "DESeq2"
## [430] "SummarizedExperiment" "DelayedArray" "BiocParallel"
## [433] "matrixStats" "Biobase" "GenomicRanges"
## [436] "GenomeInfoDb" "IRanges" "S4Vectors"
## [439] "BiocGenerics" "parallel" "stats4"
## [442] "stats" "graphics" "grDevices"
## [445] "utils" "datasets" "methods"
## [448] "base"
Set working directory to the folder that contains only gene count txt files
# Generate a tx2gene object for matrix generation
edb <- EnsDb.Mmusculus.v79
transcriptsID <- as.data.frame(transcripts(edb))
tx2gene <- as.data.frame(cbind(transcriptsID$tx_id, transcriptsID$tx_id))
# Generate DESeqData using the counting result generated using Salmon
setwd("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/RNA-Seq/Mouse colon epithelium/Gene Counts")
inDir = getwd()
countFiles = list.files(inDir, pattern=".sf$", full.names = TRUE)
basename(countFiles)
## [1] "LIB037245_GEN00137835.sf" "LIB037245_GEN00137836.sf"
## [3] "LIB037245_GEN00137837.sf" "LIB037245_GEN00137838.sf"
## [5] "LIB037245_GEN00137839.sf" "LIB037245_GEN00137840.sf"
## [7] "LIB037245_GEN00137841.sf" "LIB037245_GEN00137842.sf"
names(countFiles) <- c('Fabp_1','Fabp_2','Fabp_3','Fabp_4','KrasG12D_1','KrasG12D_2','KrasG12D_3','KrasG12D_4')
txi.salmon <- tximport(countFiles, type = "salmon", tx2gene = tx2gene, ignoreTxVersion = TRUE)
## reading in files with read_tsv
## 1 2 3 4 5 6 7 8
## transcripts missing from tx2gene: 27668
## summarizing abundance
## summarizing counts
## summarizing length
DESeqsampletable <- data.frame(condition = c('control','control','control','control','experimental','experimental','experimental','experimental'))
DESeqsampletable$gender <- factor(c("F", "M", "M", "M", "F", "F", "F", "M"))
rownames(DESeqsampletable) <- colnames(txi.salmon$counts)
ddsHTSeq<- DESeqDataSetFromTximport(txi.salmon, DESeqsampletable, ~ gender + condition)
## using counts and average transcript lengths from tximport
ddsHTSeq_norm <- estimateSizeFactors(ddsHTSeq)
## using 'avgTxLength' from assays(dds), correcting for library size
ddsHTSeq_norm <- DESeq(ddsHTSeq_norm)
## using pre-existing normalization factors
## estimating dispersions
## gene-wise dispersion estimates
## mean-dispersion relationship
## final dispersion estimates
## fitting model and testing
ddsHTSeq_analysis <- results(ddsHTSeq_norm, contrast = c("condition", "experimental", "control"))
ddsHTSeq_analysis <- lfcShrink(ddsHTSeq_norm, contrast = c("condition", "experimental", "control"), res = ddsHTSeq_analysis)
## using 'normal' for LFC shrinkage, the Normal prior from Love et al (2014).
## additional priors are available via the 'type' argument, see ?lfcShrink for details
MA plot was generated to inspect the correct shrinkage of LFC.
plotMA(ddsHTSeq_analysis)
Data is transformed and pseudocount is calculated.
rawCountTable <- as.data.frame(DESeq2::counts(ddsHTSeq_norm, normalized = TRUE))
pseudoCount = log2(rawCountTable + 1)
grid.arrange(
ggplot(pseudoCount, aes(x= Fabp_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "Fabp_1"),
ggplot(pseudoCount, aes(x= Fabp_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "Fabp_2"),
ggplot(pseudoCount, aes(x= Fabp_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "Fabp_3"),
ggplot(pseudoCount, aes(x= Fabp_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "Fabp_4"), nrow = 2)
grid.arrange(
ggplot(pseudoCount, aes(x= KrasG12D_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_1"),
ggplot(pseudoCount, aes(x= KrasG12D_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_2"),
ggplot(pseudoCount, aes(x= KrasG12D_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_3"),
ggplot(pseudoCount, aes(x= KrasG12D_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Transcripts") +
geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_4"), nrow = 2)
Check on the gene count distribution across all genes.
#Boxplots
suppressMessages(df <- melt(pseudoCount, variable_name = "Samples"))
df <- data.frame(df, Condition = substr(df$Samples,1,4))
ggplot(df, aes(x=Samples, y=value, fill = Condition)) + geom_boxplot() + xlab("") +
ylab(expression(log[2](count+1))) + scale_fill_manual(values = c("#619CFF", "#F564E3")) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
#Histograms and density plots
ggplot(df, aes(x=value, colour = Samples, fill = Samples)) + ylim(c(0, 0.25)) +
geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
theme(legend.position = "top") + xlab(expression(log[2](count+1)))
### Generate MA plots MA plots are used to check for imbalance in sequencing depth between samples of the same condition. I did not generate MA plot for all library pairs. But the example pairs I selected show that there are imbalance in sequencing depth, but the imbalance is quite random and this is common in RNA-Seq datasets.
## WT1 vs WT2
x = pseudoCount[, 1]
y = pseudoCount[, 2]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)
suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "Fabp_1 vs Fabp_2"))
## WT1 vs WT3
x = pseudoCount[, 1]
y = pseudoCount[, 3]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)
suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "Fabp_1 vs Fabp_3"))
## G12D_1 vs G12D_2
x = pseudoCount[, 5]
y = pseudoCount[, 6]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)
suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_2"))
## G12D_1 vs G12D_3
x = pseudoCount[, 5]
y = pseudoCount[, 7]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)
suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_3"))
This is the sanity check step to confirm that under a un-supervised clustering, WT and G12D samples will cluster together. For some reason, the code is giving error when try to plot this heatmap in RStudio, so I created a pdf file that contains the heatmap in the Analysis folder named Hierchical Clustering.pdf
ddsHTSeq_transform <- varianceStabilizingTransformation(ddsHTSeq_norm)
rawCountTable_transform <- as.data.frame(assay(ddsHTSeq_transform))
pseudoCount_transform = log2(rawCountTable_transform + 1)
mat.dist = pseudoCount_transform
mat.dist = as.matrix(dist(t(mat.dist)))
mat.dist = mat.dist/max(mat.dist)
setwd("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/RNA-Seq/Mouse colon epithelium/Analysis")
png('Hierchical_Clustering_transcript_level.png')
cim(mat.dist, symkey = FALSE, margins = c(6, 6))
suppressMessages(dev.off())
## quartz_off_screen
## 2
Final output is following:
I performed PCA analysis on all datasets to confirm that samples from the same condition group together. This step has to be performed using varianceStabelizingTransformed dataset, so that the high variance in genes with low counts will not skew the data.
The top 500 most variable genes are selected for PCA analysis.
plotPCA(ddsHTSeq_transform, intgroup = "condition", ntop = 500)
This step removes all genes with 0 counts across all samples, output a csv file and also generate a density plot using filtered dataset.
keep <- rowSums(rawCountTable) > 0
filterCount <- pseudoCount[keep,]
df <- melt(filterCount, variable_name = "Samples")
## Using as id variables
df <- data.frame(df, Condition = substr(df$Samples,1,4))
detected_raw_count_norm <- rawCountTable[keep,]
write.csv(detected_raw_count_norm, "normalized_raw_transcript_counts.csv")
ggplot(df, aes(x=value, colour = Samples, fill = Samples)) +
geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
theme(legend.position = "top") + xlab("pseudocounts")
This step generates the analysis file that contains results from differential analysis.
write.csv(as.data.frame(ddsHTSeq_analysis[keep,]), "Differential Analysis_transcript_level.csv")
Genes that were not detected were removed from the list. Genes with padj < 0.05 were considered significantly dysregulated. Their normalized counts were z-scored and used for plotting the heatmap.
suppressMessages(library(mosaic))
rawCountTable_transform_detected <- rawCountTable_transform[keep,]
dif_analysis <- as.data.frame(ddsHTSeq_analysis)[keep,]
sig_dif <- subset(dif_analysis, dif_analysis$padj < 0.05)
sig_index <- c()
for (i in 1:dim(sig_dif)[1]) {
sig_index <- c(sig_index ,grep(rownames(sig_dif)[i], rownames(rawCountTable_transform_detected)))
}
sig_count <- rawCountTable_transform_detected[sig_index,]
sig_dif <- cbind(sig_dif, sig_count)
for (i in 1:dim(sig_dif)[1]) {
sig_dif[i,7:14] <- zscore(as.numeric(sig_dif[i,7:14]))
}
my_palette <- colorRampPalette(c("red", "white", "blue"))(256)
heatmap_matrix <- as.matrix(sig_dif[,7:14])
png('G12D vs WT colon epithelium transcript level RNASeq.png',
width = 300,
height = 600,
res = 100,
pointsize = 8)
heatmap.2(heatmap_matrix,
main = "Colon epithelium RNASeq",
density.info = "none",
key = TRUE,
lhei = c(1,7),
col=my_palette,
cexCol = 1,
margins = c(8,2),
trace = "none",
dendrogram = "both",
labRow = FALSE,
keysize = 2,
ylab = "Genes",
Colv = "NA")
dev.off()
## quartz_off_screen
## 2
Final output is
# Scatter plot
detected_pseudocount <- pseudoCount[keep,]
dif_analysis$KrasG12D_mean <- rowMeans(detected_pseudocount[,5:8])
dif_analysis$KrasWT_mean <- rowMeans(detected_pseudocount[,1:4])
ggplot(dif_analysis, aes(x = KrasWT_mean, y = KrasG12D_mean)) +
xlab("WT_Average(log2)") + ylab("G12D_Average(log2)") +
geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
labs(title = "WT vs G12D Scatter Plot")
# MA plot
ggplot(dif_analysis, aes(x = log(baseMean,2), y = log2FoldChange,)) +
xlab("Average Expression") + ylab("LFC") +
geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
labs(title = "WT vs G12D MA Plot")
# Volcano Plot
ggplot(dif_analysis, aes(x = log2FoldChange, y = -log(padj,10))) +
xlab("LFC") + ylab("-log10(P value)") +
geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "black") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
labs(title = "WT vs G12D Volcano Plot") +
xlim(-3,3)
## Warning: Removed 32607 rows containing missing values (geom_point).
## Warning: Removed 68 rows containing missing values (geom_point).
## Warning: Removed 30 rows containing missing values (geom_point).